package com.car.untils.SMS;

import org.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author shkstart
 * @create 2021-07-08 17:42
 */
@RestController
public class sendMessage {
    //点击发送验证码
    @GetMapping("/sendMs")
    public String sendMs (HttpServletRequest request, String phoneNumber){
        if(phoneNumber!=null&&!phoneNumber.equals("")){
            String s = SMSUtil.sendSMS(request,phoneNumber);
            return s;
        }else{
            return "error";
        }
    }
    //点击注册
    @GetMapping("/register")
    public Object register(HttpServletRequest request, String Code) {
        JSONObject json = (JSONObject)request.getSession().getAttribute("MsCode");
        if(!json.getString("Code").equals(Code)){
            return "验证码错误";
        }
        //我这里模拟了一分钟
        if((System.currentTimeMillis() - json.getLong("createTime")) > 1000 * 60 * 1){
            return "验证码过期";
        }
        //将用户信息存入数据库、这里省略
        return "success";
    }

}
